package com.hkzhao.shixun.service.impl;

import com.hkzhao.shixun.mbg.mapper.AdminMapper;
import com.hkzhao.shixun.mbg.mapper.CoreuserMapper;
import com.hkzhao.shixun.mbg.mapper.UserpermissionMapper;
import com.hkzhao.shixun.mbg.mapper.XwouserMapper;

import com.hkzhao.shixun.mbg.model.Coreuser;
import com.hkzhao.shixun.mbg.model.CoreuserExample;
import com.hkzhao.shixun.mbg.model.Userpermission;
import com.hkzhao.shixun.mbg.model.UserpermissionExample;
import com.hkzhao.shixun.service.CoreUserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <h3>j2ee</h3>
 * <p>登录业务的实现</p>
 *
 * @author : hkzhao
 * @date : 2020-06-05 16:14
 **/
@Service
public class CoreUserServiceImpl implements CoreUserSerivce {
    @Autowired(required = false)
    private CoreuserMapper coreuserMapper;
    @Autowired(required = false)
    private UserpermissionMapper userpermissionMapper;
    @Autowired(required = false)
    private XwouserMapper  xwouserMapper;
    @Autowired(required = false)
    private AdminMapper adminMapper;

    @Override
    public String getPassword(String username) {
        CoreuserExample coreuserExample = new CoreuserExample();
        coreuserExample.createCriteria().andUsernameEqualTo(username);
        List<Coreuser> list = coreuserMapper.selectByExample(coreuserExample);
        if(list!=null&&list.size()>0){
            if(list.get(0).getPosition().equals("1")){
                return adminMapper.selectByPrimaryKey(username).getPassword();
            }else if(list.get(0).getPosition().equals("0")){
                return xwouserMapper.selectByPrimaryKey(username).getPassword();
            }else {
                return "";
            }
        }
        return "";
    }

    @Override
    public List<Userpermission> getPermissionList(String token_id) {
        UserpermissionExample userPermissionExample = new UserpermissionExample();
        userPermissionExample.createCriteria().andTokenidEqualTo(token_id);
        List<Userpermission> list = userpermissionMapper.selectByExample(userPermissionExample);
        if(list!=null) {
            return list;
        }
        return null;
    }

    @Override
    public Coreuser getCoreUserByusername(String username) {
        CoreuserExample coreuserExample = new CoreuserExample();
        coreuserExample.createCriteria().andUsernameEqualTo(username);
        List<Coreuser> list = coreuserMapper.selectByExample(coreuserExample);
        if(list!=null&list.size()>0){
            return list.get(0);
        }
        return null;
    }
}